package com.xxjh.brs.map.vo;

import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

/**
 * @author CHENCHEN
 * @title a
 * @company 新兴际华科技（天津）有限公司
 * @create 2024-06-17 16:47
 */
@ApiModel(description = "下载进度实体")
public class DownloadProgress {

    @ApiModelProperty(value = "总片数", name="totalTiles")
    private final int totalTiles;//总片数

    @ApiModelProperty(value = "已下载片数", name="downloadedTiles")
    private int downloadedTiles;//已下载片数

    @ApiModelProperty(value = "下载状态,例如：completed = 完成; loading = 下载中", name="status")
    private String status;//下载状态

    @ApiModelProperty(value = "下载进度，例如 33.33 %", name="percentage")
    private String percentage;//下载进度

    @ApiModelProperty(value = "总大小，例如 4.33G", name="totalSize")
    private String totalSize;//总大小

    @ApiModelProperty(value = "当前下载速度，例如 123 B/s 自动转换", name="currentSpeed")
    private String currentSpeed; // 当前下载速度

    @JsonIgnore
    private long lastUpdateTime; // 上次更新时间戳

    @JsonIgnore
    private long lastDownloadedTiles; // 上次更新时的已下载瓦片数

    public DownloadProgress(int totalTiles) {
        this.totalTiles = totalTiles;
        this.downloadedTiles = 0;
        this.status = "loading";
        this.lastUpdateTime = System.currentTimeMillis(); // 初始化更新时间
        this.lastDownloadedTiles = 0;
        this.currentSpeed = "0 B/s"; // 初始速度设为0 B/s
    }

    public synchronized void incrementDownloaded() {
        downloadedTiles++;
    }

    // 新增或修改方法来记录更新时间与下载数量
    public void updateTimeAndDownloadedTiles() {
        this.lastUpdateTime = System.currentTimeMillis();
        this.lastDownloadedTiles = this.downloadedTiles;
    }

    // 获取当前速度的方法
    public String getCurrentSpeed() {
        return currentSpeed;
    }

    // 设置当前速度的方法
    public void setCurrentSpeed(String currentSpeed) {
        this.currentSpeed = currentSpeed;
    }

    public int getTotalTiles() {
        return totalTiles;
    }

    public int getDownloadedTiles() {
        return downloadedTiles;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getStatus() {
        return status;
    }

    public String getPercentage() {
        return percentage;
    }

    public void setPercentage(String percentage) {
        this.percentage = percentage;
    }

    public String getTotalSize() {
        return totalSize;
    }

    public void setTotalSize(String totalSize) {
        this.totalSize = totalSize;
    }

    public long getLastUpdateTime() {
        return lastUpdateTime;
    }

    public void setLastUpdateTime(long lastUpdateTime) {
        this.lastUpdateTime = lastUpdateTime;
    }

    public long getLastDownloadedTiles() {
        return lastDownloadedTiles;
    }

    public void setLastDownloadedTiles(long lastDownloadedTiles) {
        this.lastDownloadedTiles = lastDownloadedTiles;
    }
}
